package com.ocom.mqsimple.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Lazy
@Component
@Configuration
public class UnicomAccTypeMqConfig {

    // 业务队列
    public static final String UNICOM_QUEUE = "unicom_acc_type_queue";

    // 业务交换机
    public static final String UNICOM_EXCHANGE = "unicom_acc_type_exchange";

    //声明一个业务队列
    @Bean
    public Queue unicomAccTypeQueue() {
        Map<String, Object> args = new HashMap<>();
        // 声明  死信队列Exchange
//        args.put("x-dead-letter-exchange", UNICOM_DIE_EXCHANGE);
//        // 设置死信routingKey
//        args.put("x-dead-letter-routing-key", "dieRoutingKeys");

        //优先级队列
        args.put("x-max-priority", 100);

        return new Queue(
                UNICOM_QUEUE,
                true,
                false,
                false, args);
    }

    //声明一个业务交换机
    @Bean
    public TopicExchange unicomAccTypeExchange() {
        return new TopicExchange(UNICOM_EXCHANGE);
    }

    //将业务队列和业务交换机绑定
    @Bean
    public Binding unicomAccTypeBindingDirect() {
        return BindingBuilder.bind(unicomAccTypeQueue()).to(unicomAccTypeExchange()).with("routingKeys");
    }


}

